{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑轮播图</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item ">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">标题：</label>
                            <div class="layui-input-block">
                                <input type="text" name="banner_title" placeholder="标题"  value="{$banner.banner_title}" class="layui-input ">
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择分类：</label>
                            <div class="layui-input-block">
                                <select name=""  lay-search="" lay-filter="types" id="types" lay-verify="required">
                                    <option value="0">---- 请选择分类 ----</option>
                                    {foreach name="types" item="t"}
                                    <option value="{$t.t_id}" {if $t.t_id==$typeid}selected{/if}>{$t.t_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择品牌：</label>
                            <div class="layui-input-block">
                                <select name="banner_pp_id"  lay-search="" lay-filter="pps" id="type_pps" lay-verify="required">
                                    <option value="0">---- 请选择品牌 ----</option>
                                    {foreach name="pps" item="v"}
                                    <option value="{$v.pp_id}" {if $v.pp_id==$banner.banner_pp_id}selected{/if}>{$v.pp_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">选择门店：</label>
                            <div class="layui-input-block">
                                <select name="banner_s_id"  lay-search="" lay-verify="required" id="type_sss">
                                    {foreach name="sss" item="v"}
                                    <option value="{$v.s_id}" {if $v.s_id==$banner.banner_s_id}selected{/if}>{$v.s_name}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {if $banner.banner_type == 1}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">图片：</label>
                            <input type="hidden" name="banner_img" id="lay-img" lay-verify="image" value="{$banner.banner_img}">
                            <div class="layui-input-block">
                                <div id="lay-upload">上传图片</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览图：
                                    <div class="layui-upload-list" id="lay-list">
                                        <img class="layui-append-img" src="{$banner.banner_img}" onerror="this.src='/static/admin/images/no_img.jpg'">
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">内容：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$banner.banner_content}</p>
                            </div>
                        </div>
                        {else /}
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">视频：</label>
                            <input type="hidden" name="video" id="lay-img2" lay-verify="image" value="{$banner.banner_img}">
                            <div class="layui-input-block">
                                <div id="lay-upload2">上传视频</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览：
                                    <div class="layui-upload-list" id="lay-list2">
                                        <video class="layui-append-img" src="{$banner.banner_img}" controls="controls"></video>
                                    </div>
                                </blockquote>
                            </div>
                        </div>
                        {/if}
                        <input type="hidden" value="{$banner.banner_id}" name="banner_id">
                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    var editor = wk.wang({elem:'#LAY_editor'});
    wk.uploadImg({size:5,type:'png,jpg,jpeg',url:"{:url('Upload/upload')}",domain:""});
    wk.uploadImg({size:500,num:2,type:'MP4,Mp4,mP4,mp4',url:"{:url('Upload/upload')}",video:3}); //视频
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
//        form.verify({
//            editor:function(value,item){
//                if(editor.txt.html() == '<p><br></p>'){
//                    return '请填写内容';
//                }
//            }
//        });
        form.on('submit(component-form-element)', function (data) {
            data.field.banner_content = editor.txt.html();
            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('bannerEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        wk.success(res.msg,"{:url('Banner/index')}")
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
        form.on('select(types)', function(data){
            $.ajax({
                url:"{:url('admin/Store/getDatas')}",
                dataType:"json",
                data:'t_id=' + data.value,
                type:'post',
                success:function(res){
                    var opt = '';
                    $.each(res.msg,function(key,vo){
                        opt = opt+"<option value="+vo.pp_id+">"+vo.pp_name+"</option>";
                    });
                    $("#type_pps").empty();
                    $("#type_pps").append('<option value="0">---- 请选择品牌 ----</option>');
                    $("#type_pps").append(opt);
                    form.render('select');
                }
            })
        });
        form.on('select(pps)', function(data){
            $.ajax({
                url:"{:url('admin/Cases/getDatas')}",
                dataType:"json",
                data:'pp_id=' + data.value,
                type:'post',
                success:function(res){
                    var opt = '';
                    $.each(res.msg,function(key,vo){
                        opt = opt+"<option value="+vo.s_id+">"+vo.s_name+"</option>";
                    });
                    $("#type_sss").empty();
                    $("#type_sss").append(opt);
                    form.render('select');
                }
            })
        });
    });
</script>

</body>
</html>
